package com.bloveoacom.weichi.fragment;

import android.os.Bundle;
import android.view.View;

import com.bloveoacom.base.BaseFragment;
import com.bloveoacom.base.BaseListFragment;
import com.bloveoacom.util.ActivityUtil;
import com.bloveoacom.util.Constant;
import com.bloveoacom.util.NumberUtil;
import com.bloveoacom.weichi.R;
import com.bloveoacom.weichi.activity.PostDetailActivity;
import com.bloveoacom.weichi.adapter.MyPostAdapter;
import com.bloveoacom.weichi.bean.NewsPostBean;
import com.bloveoacom.weichi.bean.PostCoinBean;
import com.bloveoacom.weichi.contract.MineContract;
import com.bloveoacom.weichi.contract.PostListContract;
import com.bloveoacom.weichi.model.MineModel;
import com.bloveoacom.weichi.model.PostListModel;
import com.bloveoacom.weichi.presenter.MinePresenter;
import com.bloveoacom.weichi.presenter.PostListPresenter;
import com.bloveoacom.weight.LlkjToolBar;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.gyf.barlibrary.ImmersionBar;

import java.util.ArrayList;

import butterknife.BindView;

/**
 * author: zhu.px
 * e-mail: 1271901673@qq.com
 * time  : 2018/5/8
 * desc  : 我的
 */
public class PostListFragment extends BaseListFragment<PostListPresenter, PostListModel,MyPostAdapter> implements PostListContract.View {

    private int sort=0;

    public static PostListFragment newInstance(int sort) {
        Bundle args = new Bundle();
        PostListFragment fragment = new PostListFragment();
        args.putInt(Constant.DATA,sort);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public int getLayoutResId() {
        return R.layout.layout_refresh;
    }



    @Override
    public void initView() {
        super.initView();
    }

    @Override
    protected void initSetting() {
        mAdapter = new MyPostAdapter(R.layout.rv_item_post2,new ArrayList<NewsPostBean>());
        openLoadMore();
    }

    @Override
    public void initData() {

    }

    @Override
    public void getBundleExtras(Bundle extras) {
        sort = extras.getInt(Constant.DATA);
    }

    @Override
    public void initListener() {
        mAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                Bundle bundle = new Bundle();
                bundle.putInt(PostDetailActivity.COINID, NumberUtil.getIntByStr(((NewsPostBean) adapter.getData().get(position)).coinId));
                ActivityUtil.startActivity(mContext, PostDetailActivity.class, bundle);
            }
        });
    }



    @Override
    public void loadMoreFail() {

    }
    @Override
    public void getSuccess(PostCoinBean bean) {
        loadDataComplete(bean.getData());
    }

    @Override
    public String getSort() {
        return String.valueOf(sort);
    }
}
